package com.bitcat.customviewdemo;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class MyView extends View {

    private Paint paint;

    //构造方法  两个参数，一般在XML布局当中使用
    public MyView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
//        paint.setColor(getResources().getColor(R.color.red));

        paint.setColor(Color.RED);
        paint.setTextSize(25);
//        paint.setStyle(Paint.Style.FILL);
//        paint.setStrokeWidth(2);
    }


    @Override
    protected void onDraw(@NonNull Canvas canvas) {
        super.onDraw(canvas);

//        canvas.drawColor(Color.BLACK);

//        //绘制矩形
//        canvas.drawRect(100,0,200,100,paint);
//        //绘制圆角矩形
//        canvas.drawRoundRect(100,150,200,250,10,10,paint);
//
//        canvas.drawLine(0,0,200,200,paint);
//
//        //绘制矩形
//        canvas.drawRect(100,0,200,100,paint);
//
//        canvas.drawCircle(120,400,100,paint);

        //椭圆
//        canvas.drawOval(0,0,200,100,paint);

        //圆
//        canvas.drawOval(0,0,200,200,paint);

//        canvas.drawArc(0,0,200,200,0,90,true,paint);


//        Bitmap srcBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.sweet);
//        Bitmap bitmap = Bitmap.createScaledBitmap(srcBitmap, 200, 200, true);
//
//        canvas.drawBitmap(bitmap,0,0,paint);

        canvas.drawText("比特猫编程",100,100,paint);
    }
}
